package com.chima.service.impl;

import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import com.chima.dao.DepartmentDao;
import com.chima.domain.Department;
import com.chima.domain.HsCheckDepartment;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.service.DepartmentService;

public class DepartmentServceImp implements DepartmentService{
	private   DepartmentDao departmentDao;
	
	public DepartmentDao getDepartmentDao() {
		return departmentDao;
	}
	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}
	public PageResponseBean findDepartment(PageRequestBean pageRequestBean) {
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults = pageRequestBean.getLimit();
		int total = departmentDao.findByTotalCount();
		// 获取分页查询条件
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Department.class);
//		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<Department> departments= departmentDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(departments);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public void saveDepartment(Department department) {
		departmentDao.save(department);
		
	}

	public void updateDepartment(Department department) {
		departmentDao.update(department);
		
	}

	public void deleteDepartment(int id) {
		departmentDao.delete(id);
	}

	public Department findByName(String name) {
		return departmentDao.findByName(name);
	}
	public Department findByIdAndflag(int id, int flag) {
		return  departmentDao.findByIdAndflag(id, flag);
	}

	public List<Department>  findByflag( int flag){
		return departmentDao.findByflag(flag);
	}
	public Department findById(int deptId) {
		return departmentDao.findById(deptId);
	}
	public List<Department> findAll() {
			
			return departmentDao.findAll();
		}
	@Override
	public List<HsCheckDepartment> findHsCheckDepartmentBymonth(
			String searchdate1) {
		// TODO Auto-generated method stub
		return departmentDao.findHsCheckDepartmentBymonth(searchdate1);
	}
	@Override
	public HsCheckDepartment findhsCheckDepartmentByid(int parseInt) {
		// TODO Auto-generated method stub
		return departmentDao.findhsCheckDepartmentByid( parseInt);
	}
	@Override
	public void addhsCheckDepartment(HsCheckDepartment hsCheckDepartment) {
		// TODO Auto-generated method stub
		departmentDao.addhsCheckDepartment(hsCheckDepartment);
	}
	@Override
	public List<Department> findListAllzhuyuanDepartment() {
		// TODO Auto-generated method stub
		return departmentDao.findListAllzhuyuanDepartment();
	}
}
